home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 8614 / 8614.xpi / modules / application / VersionsManager.jsm < prev   
Encoding:
Text File  |  2010-02-10  |  4.9 KB  |  147 lines

  1. // DO NOT import this into the global namespace, but instead
  2. // import it into your own namespace wrapper
  3.  
  4. var EXPORTED_SYMBOLS = ["VERSIONS_MANAGER"];
  5.  
  6. Components.utils.import("resource://glydo/utils/prototype_xul_1_6_0_3_modified.jsm");
  7. Components.utils.import("resource://glydo/utils/Utils.jsm");
  8. Components.utils.import("resource://glydo/utils/Prefs.jsm");
  9. Components.utils.import("resource://glydo/utils/WindowUtils.jsm");
  10. Components.utils.import("resource://glydo/storage/LoggingDB.jsm");
  11. Components.utils.import("resource://glydo/ClientInfo.jsm");
  12. Components.utils.import("resource://glydo/application/ReportsManager.jsm");
  13.  
  14. //The quit application observer topic
  15. const OBSERVER_TOPIC_QUIT_APPLICATION = "quit-application-requested";
  16. // The extension manager action requested observer topic
  17. const OBSERVER_TOPIC_EM_ACTION_REQUESTED = "em-action-requested";
  18.  
  19. var WELCOME_PAGES_BY_UPGRADE_VERSIONS = [
  20.      {version: "0", url: "http://www.glydo.com/welcome/0.9.19/welcome.html"},
  21.      {version: "0.9.1debug", url: "http://www.glydo.com/welcome/0.9.19/upgrade.html"},
  22.      {version: "0.9.20debug", url: null}
  23. ];
  24.                                                                       
  25. var VERSIONS_MANAGER = ({
  26.     
  27.     init: function() {
  28.         this.pendingUninstall = false;
  29.         this.pendingDisable = false;
  30.         this.getJustUpgradedFromVersion();
  31.         this.registerObservers();
  32.     },
  33.     
  34.     registerObservers: function() {
  35.         var observerService = Components.classes["@mozilla.org/observer-service;1"].
  36.           getService(Components.interfaces.nsIObserverService);
  37.         observerService.addObserver(this, OBSERVER_TOPIC_QUIT_APPLICATION, false);
  38.         observerService.addObserver(this, OBSERVER_TOPIC_EM_ACTION_REQUESTED, false);
  39.     },
  40.     
  41.     unregisterObservers: function() {
  42.         var observerService = Components.classes["@mozilla.org/observer-service;1"].
  43.           getService(Components.interfaces.nsIObserverService);
  44.         observerService.removeObserver(this, OBSERVER_TOPIC_QUIT_APPLICATION);
  45.         observerService.removeObserver(this, OBSERVER_TOPIC_EM_ACTION_REQUESTED);
  46.     },
  47.     
  48.     observe: function(subject, topic, data) {
  49.         switch(topic) {
  50.         case OBSERVER_TOPIC_QUIT_APPLICATION:
  51.             this.cleanupIfStoppingUsage();
  52.           break;
  53.         case OBSERVER_TOPIC_EM_ACTION_REQUESTED:
  54.           this.updatePendingActions(subject, data);
  55.           break;
  56.       }
  57.     },
  58.     
  59.     cleanupIfStoppingUsage: function() {
  60.         // Note: this function may be called multiple times
  61.         if (this.pendingUninstall || this.pendingDisable) {
  62.             
  63.             REPORTS_MANAGER.sendReportForce();
  64.         }
  65.         if (!this.pendingUninstall && !this.pendingDisable) {
  66.             REPORTS_MANAGER.sendReportIfNecessary();
  67.         }
  68.         this.unregisterObservers();
  69.     },
  70.     
  71.     updatePendingActions: function(subject, data) {
  72.         subject.QueryInterface(Components.interfaces.nsIUpdateItem);
  73.         if (CLIENT_INFO.appId == subject.id) {
  74.             switch (data) {
  75.                 case "item-cancel-action":
  76.                     this.pendingUninstall = false;
  77.                     this.pendingDisable = false;
  78.                     LOGGING_DB.logUserEvent("application.install","cancel_action",null,null);
  79.                     REPORTS_MANAGER.sendReportForce();
  80.                     break;
  81.                 case "item-uninstalled":
  82.                     this.pendingUninstall = true;
  83.                     LOGGING_DB.logUserEvent("application.install","uninstall",null,null);
  84.                     REPORTS_MANAGER.sendReportForce();
  85.                     if ("http://www.glydo.com/survey/uninstall" != "") {
  86.                         WindowUtils.goToURL(null,"http://www.glydo.com/survey/uninstall");
  87.                     }
  88.                     break;
  89.                 case "item-disabled":
  90.                     this.pendingDisable = true;
  91.                     LOGGING_DB.logUserEvent("application.install","disable",null,null);
  92.                     REPORTS_MANAGER.sendReportForce();
  93.                     break;
  94.             }
  95.         }
  96.     },
  97.  
  98.     getJustUpgradedFromVersion: function() {
  99.         var last = Prefs.last_installed_version;
  100.         this.justUpgradedFromVersion = null;
  101.         if (last) {
  102.             if (last == CLIENT_INFO.version) {
  103.                 return;
  104.             }
  105.             this.justUpgradedFromVersion = last;
  106.             LOGGING_DB.logUserEvent("application.install","upgrade",
  107.                 {
  108.                     from: last
  109.                 },null);
  110.         } else {
  111.             this.justUpgradedFromVersion = "0";
  112.             LOGGING_DB.logUserEvent("application.install","install",null,null);
  113.         }
  114.         Prefs.last_installed_version = CLIENT_INFO.version;
  115.     },
  116.  
  117.     showWelcomePageIfNecessary: function(parent) {
  118.         if (this.justUpgradedFromVersion) {
  119.             var welcomePageURL = this.findWelcomePageURL();
  120.             if (welcomePageURL && welcomePageURL != "") {
  121.                 Prototype.F.delay(function() {
  122.                     WindowUtils.goToURL(parent,welcomePageURL,'new-tab');
  123.                 },1);
  124.                 
  125.             }
  126.         }
  127.     },
  128.     
  129.     findWelcomePageURL: function() {
  130.         for (var i= 0; i < WELCOME_PAGES_BY_UPGRADE_VERSIONS.length; ++i) {
  131.             var entry = WELCOME_PAGES_BY_UPGRADE_VERSIONS[i];
  132.             var c = Utils.compareVersionNumbers(this.justUpgradedFromVersion,entry.version);
  133.             if (c > 0) {
  134.                 break;
  135.             }
  136.         }
  137.         if (i < 1 || i > WELCOME_PAGES_BY_UPGRADE_VERSIONS.length) {
  138.             return null;
  139.         }
  140.         return WELCOME_PAGES_BY_UPGRADE_VERSIONS[i-1].url;
  141.     },
  142.     
  143. });
  144.  
  145. VERSIONS_MANAGER.init();
  146.  
  147.